package com.yyq.adms.hngg.bpo.impl;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yyq.adms.hngg.bpo.PeriodicalMagazineBpo;
import com.yyq.adms.hngg.dao.PeriodicalMagazineDao;
import com.yyq.adms.hngg.pojo.MagazineDetail;
import com.yyq.adms.util.JxlsUtil;
import com.yyq.adms.util.JxlsVo;
import com.yyq.adms.yyb.advance.pojo.STApply;
import com.yyq.sos.permission.LoginUser;
import com.yyq.sos.service.BaseBpoImpl;

@Service("periodicalMagazineBpo")
@Transactional
public class PeriodicalMagazineBpoImpl extends BaseBpoImpl implements
		PeriodicalMagazineBpo {
	
	private static final String AUTHOR = "作者";
	private static final String THEME = "论文名称";
	private static final String OTHER = "备注";
	
	
	private PeriodicalMagazineDao dao;
	@Resource(name="periodicalMagazineDao")
	public void setDao(PeriodicalMagazineDao dao) {
		this.dao = dao;
		super.setBaseDao(dao);
	}
	
	public String validateBatchAdd(List<Map<String, JxlsVo>> srcData, List<MagazineDetail> list,Map<String, Object> vMap, 
			LoginUser user, List<Map<String, JxlsVo>> otherOrgRepeatData){
		
		processVMap(vMap);
		StringBuffer errMsg = new StringBuffer();
		Map<String,Integer> contentRepeat=new HashMap<String,Integer>();
		int index=0;
		for (Map<String, JxlsVo> map : srcData) {
			boolean flag = validateData(index,srcData,errMsg, map,list,contentRepeat,user,otherOrgRepeatData);
			index++;
		}
		return errMsg.toString();
	}
	
	private void processVMap(Map<String, Object> vMap){
		vMap.put(THEME, 1);
		vMap.put(AUTHOR, 2);
		vMap.put(OTHER, 3);
		
	}
	
	private boolean validateData(int index, List<Map<String,JxlsVo>> srcData, StringBuffer errMsg, Map<String, JxlsVo> map,List list,
			Map<String,Integer> contentRepeat,LoginUser user, List<Map<String,JxlsVo>> otherOrgRepeatData) {
		JxlsVo articalVo = map.get(THEME);
		JxlsVo authorVo = map.get(AUTHOR);
		JxlsVo backUpVo = map.get(OTHER);
		
		boolean flag = true;
		String artical = articalVo.getContent();
		String author = authorVo.getContent();
		String backUp = backUpVo.getContent();
		
		MagazineDetail vo = new MagazineDetail();
		vo.setAuthor(author);
		vo.setTheme(artical);
		vo.setOther(backUp);
		validateBlank(errMsg, articalVo,THEME);
		validateBlank(errMsg, authorVo,AUTHOR);
		//validateBlank(errMsg, backUpVo,OTHER);
		list.add(vo);
		return flag;
	}
	
	private void validateBlank(StringBuffer errMsg, JxlsVo jVo,String key) {
		if(jVo.getContent().equals("")){
			JxlsUtil.preErrMsg(errMsg, jVo, key);
			errMsg.append("不能为空").append("<br/>");
		}
	}



}
